package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.ems.common.enums.DeviceType;
import com.econ.powercloud.ems.pojo.*;
import com.econ.powercloud.ems.pojo.DitDataVO;
import com.econ.powercloud.ems.pojo.requestVO.SingleListRequestVO;
import com.econ.powercloud.ems.service.biz.FlashNewDataService;
import com.econ.powercloud.ems.service.biz.UnitBodyDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 新版实时数据查询controller
 * @Date : 2021/11/17 17:35
 * @Modified by : zjf
 */
@RestController
@Api(tags ="新版实时数据查询")
@RequestMapping(value = "/api/v2/flashData")
public class FlashNewDataController extends ApiBaseController {

    @Autowired
    private FlashNewDataService flashNewDataService;
    @Autowired
    private UnitBodyDataService unitBodyDataService;

    @GetMapping(value = "getHomePageInfo")
    @ApiOperation(value="获取储能站首页计算数据", notes="获取储能站首页计算数据")
    @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String")
    public MsgResult<List<FlashVO>> getHomePageInfo(@RequestParam(value = "stationId") String stationId){
        return successHandler(flashNewDataService.getHomePageInfo(stationId));
    }

    @GetMapping(value = "getPCSYCDataByDeviceCode")
    @ApiOperation(value="根据PCS设备code获取PCS遥测数据", notes="根据PCS设备code获取PCS遥测数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<List<List<FlashVO>>> getPCSYCDataByDeviceCode(@RequestParam(value = "deviceCode") String deviceCode ){
        return successHandler(flashNewDataService.getDeviceTwoDimensionalYcData(deviceCode));
    }

    @GetMapping(value = "getPCSYxDataByDeviceCode")
    @ApiOperation(value="根据PCS设备code获取PCS遥信数据", notes="根据PCS设备code获取PCS遥信数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<PCSOrPCUYxVO> getPCSYxDataByDeviceCode(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getPCSOrPCUYxDataByDeviceCode(deviceCode));
    }

    @GetMapping(value = "getParallelPowerMeterDataByDeviceCode")
    @ApiOperation(value="通过并网点功率表设备查询对应数据", notes="通过并网点功率表设备查询对应数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<MeterVO> getParallelPowerMeterDataByDeviceCode(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getMeterDataByDeviceCode(deviceCode));
    }

    @GetMapping(value = "getMeasurementMeterDataByDeviceCode")
    @ApiOperation(value="通过计量电表设备code查询电表数据", notes="通过计量电表设备code查询电表数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<MeterVO> getMeasurementMeterDataByDeviceCode(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getMeterDataByDeviceCode(deviceCode));
    }

    @GetMapping(value = "getParallelPowerMeterData")
    @ApiOperation(value="获取并网点功率表数据", notes="获取并网点功率表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "equipmentId", value = "储能装置id", required = true, dataType = "String")
    })
    public MsgResult<List<MeterVO>> getParallelPowerMeterData(@RequestParam(value = "stationId") String stationId,
                                                              @RequestParam(value = "equipmentId")String equipmentId){
        return successHandler(flashNewDataService.getMeterData(stationId,equipmentId, DeviceType.MULTIFUNCTION_METER.getCode()));
    }

    @GetMapping(value = "getMeasurementMeterData")
    @ApiOperation(value="获取计量电表数据", notes="获取计量电表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "equipmentId", value = "储能装置id", required = true, dataType = "String")
    })
    public MsgResult<List<MeterVO>> getMeasurementMeterData(@RequestParam(value = "stationId") String stationId,
                                                            @RequestParam(value = "equipmentId")String equipmentId){
        return successHandler(flashNewDataService.getMeterData(stationId,equipmentId, DeviceType.MEASURING_METER.getCode()));
    }

    @GetMapping(value = "getBMUYcData")
    @ApiOperation(value="获取BMU遥测数据", notes="获取BMU遥测数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<List<List<FlashVO>>> getBMUYcData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getDeviceTwoDimensionalYcData(deviceCode));
    }

    @GetMapping(value = "getBMUYxData")
    @ApiOperation(value="获取BMU遥信数据", notes="获取BMU遥信数据")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<BMUYxVO> getBMUYxData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getBamsOrBmuYxData(deviceCode));
    }

    @GetMapping(value = "getBatteryVoltageCurve")
    @ApiOperation(value="获取蔟下所有电压集合图形", notes="获取蔟下所有电压集合图形")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "deviceCode", value = "设备code", required = true, dataType = "String")
    })
    public MsgResult<BatteryVoltageVO> getBatteryVoltageCurve(@RequestParam(value = "time") Long time, @RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(unitBodyDataService.getBatteryVoltageCurve(time,deviceCode));
    }

    @GetMapping(value = "getBatteryTemperatureCurve")
    @ApiOperation(value="获取所有包下的温度图形", notes="获取所有包下的温度图形")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "deviceCode", value = "设备code", required = true, dataType = "String")
    })
    public MsgResult<BatteryTemperatureVO> getBatteryTemperatureCurve(@RequestParam(value = "time") Long time, @RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(unitBodyDataService.getBatteryTemperatureCurve(time,deviceCode));
    }

    @GetMapping(value = "getBatteryVoltageTable")
    @ApiOperation(value="获取蔟下所有电芯电压表格", notes="获取蔟下所有电芯电压表格")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<List<BatteryVoltageTableVO>> getBatteryVoltageTable(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(unitBodyDataService.getBatteryVoltageTable(deviceCode));
    }

    @GetMapping(value = "getBatteryTemperatureTable")
    @ApiOperation(value="获取所有包下的温度表格", notes="获取所有包下的温度表格")
    @ApiImplicitParam(name = "deviceCode", value = "设备id", required = true, dataType = "String")
    public MsgResult<List<BatteryTemperatureTableVO>> getBatteryTemperatureTable(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(unitBodyDataService.getBatteryTemperatureTable(deviceCode));
    }

    @GetMapping(value = "getAirConditionerInfo")
    @ApiOperation(value="获取空调与液冷实时数据", notes="获取空调实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "equipmentId", value = "储能装置id", required = true, dataType = "String")
    })
    public MsgResult<List<AirConditionerVO>> getAirConditionerInfo(@RequestParam(value = "stationId") String stationId,
                                                                   @RequestParam(value = "equipmentId")String equipmentId){
        return successHandler(flashNewDataService.getAirConditionerInfo(stationId, equipmentId));
    }

    @GetMapping(value = "getAuxiliarySystemInfo")
    @ApiOperation(value="获取辅助系统数据", notes="获取辅助系统数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "equipmentId", value = "储能装置id", required = true, dataType = "String")
    })
    public MsgResult<List<AuxiliaryAndOtherDeviceVO>> getAuxiliarySystemInfo(@RequestParam(value = "stationId") String stationId,
                                                                             @RequestParam(value = "equipmentId")String equipmentId){
        return successHandler(flashNewDataService.getAuxiliarySystemInfo(stationId,equipmentId));
    }

    /**
     * 这个接口是svg直接把实测点号直接埋点在图中
     * @param jsonData : 与前端约定好的数据格式
     * @return
     */
    @PostMapping(value = "getSvgFlashData")
    @ApiOperation(value="获取SVG图的实时数据", notes="获取SVG图的实时数据")
    public MsgResult<List<FlashDataVO>> getSvgFlashData(@RequestBody String jsonData){
        return successHandler(flashNewDataService.getSvgFlashVO(jsonData));
    }

    /**
     * 新版线路图获取svg图实时数据
     * @return
     */
    @PostMapping(value = "new/getSvgFlashData")
    @ApiOperation(value = "新版获取SVG图的实时数据",notes = "新版获取SVG图的实时数据")
    public MsgResult<List<FlashDataVO>> getNewFlashData(@RequestBody @Validated SingleListRequestVO<DitDataVO> list){
        return successHandler(flashNewDataService.getSvgFlashVO(list.getList()));
    }

    @GetMapping(value = "getControlData")
    @ApiOperation(value="获取控制器数据", notes="获取空调实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "储能站id", required = true, dataType = "String")
    })
    public MsgResult<List<ControlVO>> getControlData(@RequestParam(value = "stationId") String stationId){
        return successHandler(flashNewDataService.getControlData(stationId));
    }

    //以下的接口是为了获取单个设备的数据
    @GetMapping(value = "getSingleAirConditionerData")
    @ApiOperation(value="获取单个空调或液冷实时数据", notes="获取单个空调或液冷实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "EMS设备code", required = true, dataType = "String")
    })
    public MsgResult<AirConditionerVO> getSingleAirConditionerData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getSingleAirConditionInfo(deviceCode));
    }

    @GetMapping(value = "getSingleAuxiliarySystemData")
    @ApiOperation(value="获取单个辅助设备数据", notes="获取单个辅助设备数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "EMS设备code", required = true, dataType = "String")
    })
    public MsgResult<AuxiliaryAndOtherDeviceVO> getSingleAuxiliarySystemData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getSingleAuxiliaryOrOtherDeviceInfo(deviceCode));
    }

    @GetMapping(value = "getSingleControlData")
    @ApiOperation(value="获取单个控制器数据", notes="获取单个控制器数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "EMS设备code", required = true, dataType = "String")
    })
    public MsgResult<ControlVO> getSingleControlData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getSingleControlData(deviceCode));
    }

    @GetMapping(value = "getSingleProtectDeviceData")
    @ApiOperation(value="获取单个保护设备数据", notes="获取单个保护设备数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "EMS设备code", required = true, dataType = "String")
    })
    public MsgResult<ProtectDeviceVO> getSingleProtectDeviceData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getSingleProtectDeviceData(deviceCode));
    }

    @GetMapping(value = "getSingleOtherDeviceData")
    @ApiOperation(value="获取单个其他类型设备数据", notes="获取单个其他类型设备数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "EMS设备code", required = true, dataType = "String")
    })
    public MsgResult<AuxiliaryAndOtherDeviceVO> getSingleOtherDeviceData(@RequestParam(value = "deviceCode") String deviceCode){
        return successHandler(flashNewDataService.getSingleAuxiliaryOrOtherDeviceInfo(deviceCode));
    }
}
